#!/bin/bash
## This is my (demuredemeanor) nitrogen script for handling 1 vs multi monitors
##
## The script assumes nitrogen has been configured with at least one wallpaper
## dir already, as well as a default wallpaper.


count=$(xrandr --query | awk 'BEGIN {c=-1} / connected/ {c+=1} END {print c}')

## a zero means just one monitor, so set the saved wallpaper
## Otherwise roll the dice for multiple monitors
if [ $count -eq 0 ]; then
    nitrogen --restore
else
    i=0
    until [ $i -gt $count ]; do
        nitrogen --random --set-auto --head=$i
        ((i++))
    done
fi
